package com.bestom.multispectrallight;

import android.app.Application;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.os.Build;
import android.util.Log;

import com.bestom.multispectrallight.callback.BTGattCallback;
import com.bestom.multispectrallight.callback.BleListen;
import com.bestom.multispectrallight.util.SharedPreferencesUtil;

import java.io.File;
import java.util.HashMap;

import static android.bluetooth.BluetoothDevice.TRANSPORT_LE;

/**
 * @author ..
 */
public class ThisApplication extends Application {
    private static ThisApplication application;
    private BluetoothGatt mBluetoothGatt;

    @Override
    public void onCreate() {
        super.onCreate();
        //gattHashMap.clear();
        //isConnectMap.clear();
        application = this;
        SharedPreferencesUtil.init(this);
        File file = new File("data/data/com.bestom.multispectrallight/databases/lyc.db");
        Log.d("application", "file.exists():" + file.exists());
        if (file.exists()){
            file.delete();
        }

    }

    public static synchronized ThisApplication getApplication() {
        return application;
    }

    public BluetoothGatt getBluetoothGatt() {
        return mBluetoothGatt;
    }

    public void setBluetoothGatt(BluetoothGatt mBluetoothGatt) {
        this.mBluetoothGatt = mBluetoothGatt;
    }
    public void setBluetoothDevice(BluetoothDevice mBluetoothDevice, BleListen bleListen) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            mBluetoothGatt = mBluetoothDevice.connectGatt(getApplicationContext(),true, BTGattCallback.getInstance(bleListen), TRANSPORT_LE);
        }else {
             mBluetoothGatt= mBluetoothDevice.connectGatt(getApplicationContext(),true,BTGattCallback.getInstance(bleListen));
        }
        setBluetoothGatt(mBluetoothGatt);

    }
}
